package com.rpay.admin.controller.wallet;

import com.rpay.admin.param.wallet.PostWallet;
import com.rpay.common.dto.wallet.WalletDTO;
import com.rpay.common.dto.wallet.WalletQueryDTO;
import com.rpay.common.vo.PcsResult;
import com.rpay.service.wallet.IWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author XXX
 * @mail XXX@hotmail.com
 * @date 2018/5/17
 * @Description:系统钱包管理
 */
@RestController
@RequestMapping(value = "api/wallet")
@Validated
public class WalletController {
    @Autowired
    private IWalletService iWalletService;

    @GetMapping(value = "")
    public PcsResult list() {
        WalletQueryDTO data = iWalletService.list();
        return PcsResult.build(data);
    }

    @PostMapping(value = "")
    public PcsResult add(@Validated @RequestBody PostWallet postWallet) {
        WalletDTO walletDTO = new WalletDTO();
        walletDTO.setWalletAddr(postWallet.getWalletAddr());
        walletDTO.setSecretKey(postWallet.getSecretKey());
        walletDTO.setRemark(postWallet.getRemark());
        iWalletService.post(walletDTO);
        return new PcsResult();
    }

    @DeleteMapping(value = "/detail/{id}")
    public PcsResult delete(@PathVariable Integer id) {
        iWalletService.delete(id);
        return new PcsResult();
    }

    @PatchMapping(value = "/detail/{id}")
    public PcsResult patch(@Validated @RequestBody PostWallet postWallet, @PathVariable("id") Integer id) {
        WalletDTO walletDTO = new WalletDTO();
        walletDTO.setId(id);
        walletDTO.setWalletAddr(postWallet.getWalletAddr());
        walletDTO.setSecretKey(postWallet.getSecretKey());
        walletDTO.setRemark(postWallet.getRemark());
        iWalletService.patch(walletDTO);
        return new PcsResult();
    }

}
